﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;

using Cisoft.Cisoft3G.Model;
using Cisoft.Cisoft3G.BLL;

public partial class UserControl_ContactsControl : System.Web.UI.UserControl
{
    private string _strc = string.Empty;
    public string strC
    {
        get { return this._strc; }
        set { this._strc = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindTree(0, (TreeNode)null);
        }
    }

    #region 绑定TreeView数据
    //绑定TreeView数据
    //private void BindTree(int pid, TreeNode node)
    //{
    //    List<ContactGroupMO> modelList = new ContactGroupBO().GetModelList(" CG_ParentID = " + pid + " order by CG_Order desc");
    //    foreach (ContactGroupMO model in modelList)
    //    {
    //        TreeNode tn = new TreeNode();
    //        if (node == null)
    //        {
    //            tn = new TreeNode();
    //            tn.Text = "<a style='text-decoration:none;' href='GetContactsHandler.ashx?ContactGroupID=" + model.CG_ContactGroupID + "'>" + model.CG_GroupName + "</a>";
    //            tvContactsGroup.Nodes.Add(tn);
    //            BindTree(model.CG_ContactGroupID, tn);
    //        }
    //        else
    //        {
    //            tn = new TreeNode();
    //            tn.Text = "<a style='text-decoration:none;' href='GetContactsHandler.ashx?ContactGroupID=" + model.CG_ContactGroupID + "'>" + model.CG_GroupName + "</a>";
    //            node.ChildNodes.Add(tn);
    //            BindTree(model.CG_ContactGroupID, tn);
    //        }
    //    }
    //}
    private void BindTree(int pid, TreeNode node)
    {
        List<ContactGroupMO> modelList = new ContactGroupBO().GetModelList(" CG_ParentID = " + pid + " order by CG_Order desc");
        foreach (ContactGroupMO model in modelList)
        {
            TreeNode tn = new TreeNode();
            if (node == null)
            {
                tn = new TreeNode();
                //tn.Text = "<a style='text-decoration:none;' href='GetContactsHandler.ashx?ContactGroupID=" + model.CG_ContactGroupID + "'>" + model.CG_GroupName + "</a>";
                tn.Text = "<a style='text-decoration:none;' href='" + Request.ApplicationPath + "/UserControl/GetContactsHandler.ashx?ContactGroupID=" + model.CG_ContactGroupID + "'>" + model.CG_GroupName + "</a>";
                tn.NavigateUrl = "javascript:void(0);";
                tvContactsGroup.Nodes.Add(tn);
                BindTree(model.CG_ContactGroupID, tn);
            }
            else
            {
                tn = new TreeNode();
                //tn.Text = "<a style='text-decoration:none;' href='GetContactsHandler.ashx?ContactGroupID=" + model.CG_ContactGroupID + "'>" + model.CG_GroupName + "</a>";
                tn.Text = "<a style='text-decoration:none;' href='" + Request.ApplicationPath + "/UserControl/GetContactsHandler.ashx?ContactGroupID=" + model.CG_ContactGroupID + "'>" + model.CG_GroupName + "</a>";
                tn.NavigateUrl = "javascript:void(0);";
                node.ChildNodes.Add(tn);
                BindTree(model.CG_ContactGroupID, tn);
            }
        }
    }
    #endregion

    #region 通讯录 确定添加联系人
    protected void btnConfirm_Click(object sender, EventArgs e)
    {
        //if (string.IsNullOrEmpty(tb.Text))
        //{
        //    Session["Contacts"] = hih_right.Value;
        //}
        //else
        //{
        //    Session["Contacts"] = tb.Text.TrimEnd(',') + "," + hih_right.Value;
        //}
        Session["Contacts"] = hih_right.Value;
    }
    #endregion 
}
